// 账号信息数据访问层
module.exports = {
    // 通过用户名获取用户
    getAccountByUsername:function (app, username, cb) {
        let db = app.get("mongodb");
        db.collection("account")
            .find({username:username})
            .toArray(function(err, result){
                if (result.length > 0) {
                    cb(err, result[0]);
                } else {
                    cb(err, null);
                }
            });
    },
    addAccount:function(app, username, cb) {
        let db = app.get("mongodb");
        db.collection("account").insertOne({
            username:username,
            nickname:username,
            gole:20000,
            gem:100
        }, function(err, res){
            cb(err);
        });
    },
    rename:function(app, uid, nickname, cb) {
        let db = app.get("mongodb");
        db.collection("account").update({
            _id:uid
        }, {
            $set:{nickname:nickname}
        },function(err, res){
            cb(err);
        });
    },
};